// pages/distribution/Withdrawal.js
const Controller = require('../controllers/controllers.js').controller;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg:"",
    money:"",
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.withdrawalList()
      this.myPromoterData()
  },
  withdrawalList(is){
    Controller.withdrawalList({page:this.data.page}).then(res=>{
      if(res.data.baseData){
        var r=res.data.baseData;
        if(is){
          r=this.data.msg
          r.list.push(...res.data.baseData.list)
        }
        
        this.setData({
          msg:r,
          page:this.data.page+1
        })

      }
    })
  },
  withdrawal(){  //提现
    // if(this.data.money.rate <= this.data.money.moneyV && this.data.money.moneyV &&this.data.money.moneyV<this.data.money.money){
      
    // }
    
    Controller.withdrawal({money:this.data.money.moneyV}).then(res=>{
      this.setData({
        page:1
      })
      this.withdrawalList()
      this.myPromoterData()

      wx.showToast({
        title: res.msg,
        duration: 2000//持续的时间
      })
    })

  },
  myPromoterData(){
    Controller.myPromoterData().then(res=>{
      if(res.data.baseData){
        this.setData({
          money:res.data.baseData
        })

        Controller.appinfo({key:"key-withdrawal-limit"}).then(res=>{
          this.setData({
            ['money.limit']:res.data.baseData.content
          })

          Controller.appinfo({key:"key-withdrawal-min-money"}).then(res=>{
            this.setData({
              ['money.rate']:res.data.baseData.content
            })
          })

        })

      }
    })

    
    
    
  },
  onChange(e) {
    this.setData({
      ['money.moneyV']: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.page <=this.data.msg.totalPage){
        this.mySubordinateUser(true);
    }else{
      console.log('没数据了')
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})